<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" th:href="@{/img/logo.ico}" href="../static/img/logo.ico" type="images/x-ico"/>

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}">
    <title>课程信息</title>
    <link rel="stylesheet" th:href="@{/fontawesome/css/font-awesome.min.css}"
          href="../../static/fontawesome/css/font-awesome.min.css">

    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,400&display=swap">

    <!-- Fontawesome CSS -->
    <link rel="stylesheet" href="../static/fontawesome/css/fontawesome.min.css"
          th:href="@{/fontawesome/css/fontawesome.min.css}">
    <link rel="stylesheet" href="../static/fontawesome/css/all.min.css" th:href="@{/fontawesome/css/all.min.css}">

    <!-- Main CSS -->
    <link rel="stylesheet" href="../static/css/back_index.css" th:href="@{/css/back_index.css}">
    <style type="text/css">
        th, td {
            white-space: nowrap;
            overflow: hidden;
            word-break: keep-all;
        }
    </style>
</head>
<body>
<div class="main-wrapper">
    <div th:replace="commons/bar::#teachermenubar(activeUri1='课程信息')"></div>
    <div class="page-wrapper">
        <div class="content container-fluid">
            <ul class="nav nav-tabs" id="myTab" role="tablist">
                <li class="nav-item" role="presentation">
                    <a class="nav-link active" id="first-tab" data-toggle="tab" href="#first" role="tab"
                       aria-controls="first"
                       aria-selected="true" style="color: black;">课程信息</a>
                </li>
                <li class="nav-item" role="presentation">
                    <a class="nav-link" id="second-tab" data-toggle="tab" href="#second" role="tab"
                       aria-controls="second"
                       aria-selected="true" style="color: black;">课程学生</a>
                </li>
            </ul>
            <div class="tab-content">
                <!-- 课程信息-->
                <div class="tab-pane fade show active" id="first" role="tabpanel" aria-labelledby="first-tab">
                    <p class="mb-2 text-muted" style="font-size: smaller">
                        为了避免课程信息错乱，我们暂停了教师修改课程信息功能，如有对课程信息的更新，请联系管理员。
                    </p>
                    <table class="table table-striped table-bordered">
                        <tr>
                            <th>课程号</th>
                            <td id="courseId"></td>
                        </tr>
                        <tr>
                            <th>名称</th>
                            <td id="courseName"></td>
                        </tr>
                        <tr>
                            <th>类型</th>
                            <td id="courseType"></td>
                        </tr>
                        <tr>
                            <th>学时</th>
                            <td id="time"></td>
                        </tr>
                        <tr>
                            <th>学分</th>
                            <td id="credits"></td>
                        </tr>
                        <tr>
                            <th>状态</th>
                            <td id="status"></td>
                        </tr>
                        <tr>
                            <th>描述</th>
                            <td id="info"></td>
                        </tr>
                    </table>
                </div>
                <!-- 课程学生-->
                <div class="tab-pane fade" id="second" role="tabpanel" aria-labelledby="second-tab">
                    <div class="fixed-table-toolbar">
                    <span class="mb-2 text-muted" style="font-size: smaller">
                        如下为所有选报此课程的学生，您可将此作为点名册。
                    </span>
                        <div class="columns columns-right btn-group pull-right">
                            <div class="keep-open btn-group" title="列">
                                <!--                                <button type="button" class="btn btn-default" href="javascript:print()" target="_self"-->
                                <!--                                   rel="external nofollow">-->
                                <!--                                    <i class="fas fa-print"></i><span class="caret"></span>-->
                                <!--                                </button>-->
                                <button class="btn btn-default" type="button" name="refresh" title="刷新"
                                        onclick="myrefresh()">
                                    <i class="fa fa-refresh"></i></button>
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <i class="fas fa-table"></i><span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        <input type="checkbox" checked="checked" id="td1" onclick="hiddenTD('td1')">学号
                                    </li>
                                    <li>
                                        <input type="checkbox" checked="checked" id="td2" onclick="hiddenTD('td2')">姓名
                                    </li>
                                    <li>
                                        <input type="checkbox" checked="checked" id="td3" onclick="hiddenTD('td3')">班级
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td4" onclick="hiddenTD('td4')">性别
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td5" onclick="hiddenTD('td5')">电话
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td6" onclick="hiddenTD('td6')">邮箱
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td7" onclick="hiddenTD('td7')">生日
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td8" onclick="hiddenTD('td8')">地址
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td9" onclick="hiddenTD('td9')">操作
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="fixed-table-container table-responsive">
                        <table class="table table-hover table-striped table-bordered" id="datas">
                            <thead>
                            <th class="td1">学号</th>
                            <th class="td2">姓名</th>
                            <th class="td3">班级</th>
                            <th class="td4" hidden="hidden">性别</th>
                            <th class="td5" hidden="hidden">电话</th>
                            <th class="td6" hidden="hidden">邮箱</th>
                            <th class="td7" hidden="hidden">生日</th>
                            <th class="td8" hidden="hidden">地址</th>
                            <th class="td9">操作</th>
                            </thead>
                            <tbody id="mytbody">
                            <tr id="template">
                                <td class="td1"></td>
                                <td class="td2"></td>
                                <td class="td3"></td>
                                <td class="td4" hidden="hidden"></td>
                                <td class="td5" hidden="hidden"></td>
                                <td class="td6" hidden="hidden"></td>
                                <td class="td7" hidden="hidden"></td>
                                <td class="td8" hidden="hidden"></td>
                                <td class="td9"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="viewStudentModal" tabindex="-1"
                 role="dialog" aria-labelledby="studentModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title"
                                id="studentModalLabel">详细信息</h5>
                            <button type="button" class="close" data-dismiss="modal"
                                    aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <table align="center">
                                <tr>
                                    <td><span style="color: red">*</span>姓名</td>
                                    <td>
                                        <input type="text" id="studentName">
                                    </td>
                                </tr>
                                <tr>
                                    <td><span style="color: red">*</span>学号</td>
                                    <td>
                                        <input type="text" id="studentId">
                                    </td>
                                </tr>
                                <tr>
                                    <td><span style="color: red">*</span>班级</td>
                                    <td>
                                        <select id="studentClassId"></select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>性别</td>
                                    <td>
                                        <input type="radio" id="boy" value="男" name="sex"><label
                                            for="boy">男</label>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="radio" id="girl" value="女" name="sex"><label
                                            for="girl">女</label>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="radio" id="null" value="其他" name="sex" disabled><label
                                            for="null">其他</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>生日</td>
                                    <td>
                                        <input type="date" id="birthday">
                                    </td>
                                </tr>
                                <tr>
                                    <td>手机号</td>
                                    <td>
                                        <input type="text" id="telephone"><br/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>常用邮箱</td>
                                    <td>
                                        <input type="text" id="email"><br/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>家庭地址</td>
                                    <td>
                                        <textarea rows="2" cols="24" id="address"></textarea>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" id="submitResetPassword">
                                重置密码
                            </button>
                            <button type="button" class="btn btn-info" id="submitUpdate">保存修改</button>
                            <button type="button" class="btn btn-danger" id="submitDelete">删除学生</button>
                            <button type="button" class="btn btn-secondary"
                                    data-dismiss="modal">关闭
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Footer -->
            <footer>
                <p>2020 &copy; 软件学院学生信息管理系统 by 郑焙元</p>
            </footer>
            <!-- /Footer -->
        </div>
    </div>
</div>
<script src="../static/js/jquery-3.5.1.min.js" th:src="@{/js/jquery-3.5.1.min.js}"></script>
<script>

    $(function () {
        CourseInit();
    });

    var CourseInit = function () {
        sendAjax('/teacher/api/course/' + [[${session.LoginUser}]], 'get', {}, function (res) {
            $("#courseId").text(res.data.courseid);
            courseid = res.data.courseid;
            $("#courseName").text(res.data.coursename);
            $("#courseType").text(switchCoursetype(res.data.coursetype));
            $("#time").text(res.data.time);
            $("#credits").text(res.data.credits);
            var today = new Date();
            var status;
            if (today > new Date(res.data.begindate)) {
                if (today < new Date(res.data.enddate)) {
                    status = "进行中";
                } else {
                    status = "已结束";
                }
            } else {
                status = "未开始";
            }
            $("#status").text(status);
            $("#info").text(res.data.info);
        }, '');
    }

    var TableInit = function () {
        sendAjax('/teacher/api/' + [[${session.LoginUser}]], 'get', {
            limit: $("#limit option:selected").val(),
            offset: $("#offset").val(),
        }, function (res) {
            if (res.data.length === 0) {
                begin = 0;
            }
            $.each(res.data, function (i, student) {
                var row = $("#template").clone();
                row.find(".td1").text(student.studentid);
                row.find(".td2").text(student.studentname);
                row.find(".td3").text(student.studentclassid);
                row.find(".td4").text(student.sex);
                row.find(".td5").text(student.telephone);
                row.find(".td6").text(student.email);
                row.find(".td7").text(student.birthday);
                row.find(".td8").text(student.address);
                let html = '<button type="button" class="btn btn-info btn-sm" data-toggle="modal" ' +
                    'data-target="#viewStudentModal" onclick="viewStudent(\'' + student.studentid + '\')">详情</button>';
                row.find(".td9").html(html);
                row.appendTo("#datas");//添加到模板的容器中
            });
            $("#template:first").remove();
        }, '');
    }

    function myrefresh() {
        $("#mytbody").children().remove();
        $("#mytbody").html('<tr id="template">\n' +
            '                                <td class="td1"></td>\n' +
            '                                <td class="td2"></td>\n' +
            '                                <td class="td3"></td>\n' +
            '                                <td class="td4" hidden="hidden"></td>\n' +
            '                                <td class="td5" hidden="hidden"></td>\n' +
            '                                <td class="td6" hidden="hidden"></td>\n' +
            '                                <td class="td7" hidden="hidden"></td>\n' +
            '                                <td class="td8" hidden="hidden"></td>\n' +
            '                                <td class="td9"></td>\n' +
            '                            </tr>');
        TableInit();
        hiddenTD("td4");
        hiddenTD("td5");
        hiddenTD("td6");
        hiddenTD("td7");
        hiddenTD("td8");
    }

    function viewStudent(studentid) {
        sendAjax('/teacher/api/student/' + studentid, 'get', {}, function (res) {
            $("#studentName").val(res.data.studentname);
            $("#studentId").val(res.data.studentid);
            var id = res.data.studentclassid;
            sendAjax("/admin/api/class", "get", {}, function (res) {
                var html = "";
                $.each(res.data, function (i, data) {
                    if (data.classid === id) {
                        html += '<option value="' + data.classid + '" selected="selected">' + data.classname + '</option>';
                    } else {
                        html += '<option value="' + data.classid + '">' + data.classname + '</option>';
                    }
                })
                $("#studentClassId").html(html);
            }, "");
            $("[name = 'sex']").each(function () {
                if ($(this).val() === res.data.sex) {
                    $(this).prop("checked", "checked");
                }
            });
            $("#birthday").val(res.data.birthday === null ? "1970-01-01" : res.data.birthday.substring(0, 10));
            $("#telephone").val(res.data.telephone);
            $("#email").val(res.data.email);
            $("#address").text(res.data.address);
        }, '');
    }

</script>
<script src="../static/js/popper.min.js" th:src="@{/js/popper.min.js}"></script>
<script src="../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>

<!-- Slimscroll JS -->
<script src="../static/js/jquery.slimscroll.min.js" th:src="@{/js/jquery.slimscroll.min.js}"></script>

<!-- Custom JS -->
<script src="../static/js/script.js" th:src="@{/js/script.js}"></script>

</body>
</html>
